<!--
 * @Author: dfh
 * @Date: 2023-12-14 15:02:51
 * @LastEditors: dfh
 * @Modified By: dfh
 * @describe: 
-->
<template>
  <cw-tree :data="data" label-field="xx" :default-expanded-keys="['41','4131','413121']"></cw-tree>
</template>

<script setup lang="ts">
import {ref} from 'vue';
import { TreeOptions } from '@cowain/components/tree';

//构建tree的数据
function createData(level = 4, parentKey = ''):TreeOptions[] {
  if (!level) return [];
  const arr = new Array(6 - level).fill(0).fill(0);
  return arr.map((_, idx: number) => {
    const key = parentKey + level + idx;
    return {
      xx: createLabel(level),
      key,
      children: createData(level - 1, key)
    }
  });
}

function createLabel(level: number): string {
  if (level === 4) return '道生一';
  if (level === 3) return '一生二';
  if (level === 2) return '二生三';
  if (level === 1) return '三生万物';
  return '';
}

const data = ref<TreeOptions[]>(createData());
console.log(data);
</script>

<style lang="scss" scoped></style>